package com.lc202407;

import java.util.ArrayList;
import java.util.List;

public class Solution3033 {
    public int[][] modifiedMatrix(int[][] matrix) {
        int max;
        int x = matrix.length;
        int y = matrix[0].length;
        List<Integer> index;
        for (int i = 0; i < y; i++) {
            max = Integer.MIN_VALUE;
            index = new ArrayList<>();
            index.clear();
            for (int j = 0; j < x; j++) {
                int num = matrix[j][i];
                if (num == -1) {
                    index.add(j);
                }
                max = Math.max(max, num);
            }
            for (Integer d : index) {
                matrix[d][i] = max;
            }
        }
        return matrix;
    }
}
